package com.personal.controller;

import com.personal.controller.result.BackCode;
import com.personal.controller.result.Result;
import com.personal.domain.HouseProp;
import com.personal.domain.HousePropPlus;
import com.personal.domain.obtain.IndustryDireTree;
import com.personal.service.HousePropService;
import com.personal.util.partDisplay.HousePropPart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: smartCommunity_springboot
 * @package: com.personal.controller
 * @className: HousePropController
 * @author: bong~
 * @description: TODO
 * @date: 2023/8/11 10:09
 * @version: 1.0
 */

@RestController
@RequestMapping("/houseProp")
public class HousePropController {


    @Autowired
    private HousePropService housePropService;

    @GetMapping("/All")
    public Result selectAll(){
        List<HouseProp> list=housePropService.selectAll();
        return new Result(list!=null? BackCode.GET_OK:BackCode.GET_ERR,list);
    }
    @GetMapping("")
    public Result selectPartAll(){
        List<HousePropPart> list=housePropService.selectPartAll();
        return new Result(list!=null?BackCode.GET_OK:BackCode.GET_ERR,list);
    }

    @GetMapping("/search")
    public Result selectPartByKey(@RequestParam("name")String name,@RequestParam("type")String type){
        List<HousePropPart> list=housePropService.selectPartByKey(name,type);
        return new Result(list!=null?BackCode.GET_OK:BackCode.GET_ERR,list);
    }

    @PostMapping()
    public Result add(@RequestBody HousePropPlus housePropPlus){
        boolean flag=housePropService.add(housePropPlus);
        return new Result(flag?BackCode.SAVE_OK:BackCode.SAVE_ERR,flag);
    }

    @GetMapping("/updateData")
    public Result getUpdateData(@RequestParam("id") int id){
        HouseProp houseProp=housePropService.getUpdateData(id);
        return new Result(houseProp!=null?BackCode.GET_OK:BackCode.GET_ERR,houseProp);
    }
    @PutMapping()
    public Result update(@RequestBody HouseProp houseProp){
        boolean flag=housePropService.update(houseProp);
        return new Result(flag?BackCode.UPDATE_OK:BackCode.UPDATE_ERR,flag);
    }

    @DeleteMapping
    public Result delete(List<Integer> ids){
        boolean flag=housePropService.delete(ids);
        return new Result(flag?BackCode.DELETE_OK:BackCode.DELETE_ERR,flag);
    }


    @GetMapping("/getByParkAreaIds")
    public Result selectByAreaIds(@RequestParam List<Integer> parkAreaIds){
        List<HousePropPart> list=housePropService.selectByAreaIds(parkAreaIds);
        return new Result(list!=null?BackCode.GET_OK:BackCode.GET_ERR,list);
    }
}
